import java.io.File;
import java.util.*;

/**
 * @ClassName EventManager
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2021/1/19 14:38
 * @Version 1.0
 */
public class EventManager {

	Map<String, List<EventListener>> listeners = new HashMap<>();

	public EventManager(String... operations) {
		for (String operation : operations) {
			this.listeners.put(operation, new ArrayList<>());
		}
	}

	public void subscribe(String eventType, EventListener listener) {
		final List<EventListener> eventListeners = listeners.get(eventType);
		eventListeners.add(listener);
	}

	public void unSubscribe(String eventType, EventListener listener) {
		final List<EventListener> eventListeners = listeners.get(eventType);
		eventListeners.remove(listener);
	}

	public void notify(String eventType, File file) {
		final List<EventListener> eventListeners = listeners.get(eventType);
		eventListeners.forEach(i->{
			i.update(eventType, file);
		});
	}
}
